<template>

</template>

<script>
import axios from 'axios'

class MyUploadAdapter {
  constructor(loader) {
    this.loader = loader;
  }

  // 启动上载过程
  upload() {
    console.log("enter upload progress")
    return this.loader.file.then((file) =>
        new Promise((resolve, reject) => {
          var formdata = new FormData();
          formdata.append("file", file);
          console.log(" data ready to upload is ");
          console.log(file)
          axios
            .post("cncec-threepart/fileUpload/newsCoverUpload", formdata)
            .then(({ data: res }) => {
              console.log("upload result: "+res);
              resolve({ default:res,});
            });
        })
    );
  }

  // 中止上载过程
  abort() {
    if (this.xhr) {
      this.xhr.abort();
    }
  }
}

function MyCustomUploadAdapterPlugin(editor) {
  editor.plugins.get("FileRepository").createUploadAdapter = (loader) => {
    // 在这里将URL配置为后端上载脚本
    return new MyUploadAdapter(loader);
  };
}
export default {
  MyUploadAdapter,
  MyCustomUploadAdapterPlugin,
};
</script>

<style>
</style>